package models

import (
	"github.com/astaxie/beego/orm"
	"time"
)

// TableName 设置BackendUser表名
func (a *KeyWord) TableName() string {
	return "key_word"
}

// BackendUser 实体类
type KeyWord struct {
	Id           int
	Type         int
	Key_name     string `orm:"size(100)"`
	Cn           string `orm:"size(600)"`
	En           string `orm:"size(600)"`
	Th           string `orm:"size(600)"`
	Created_at   time.Time `orm:"type(datetime)"`
	Updated_at   time.Time `orm:"type(datetime)"`
}

// 根据id获取单条
func KeyWordOne(id int) (*KeyWord, error) {
	o := orm.NewOrm()
	m := KeyWord{Type: id}
	err := o.Read(&m)
	if err != nil {
		return nil, err
	}
	return &m, nil
}

func KeywordAll() []*KeyWord {
	o := orm.NewOrm()
	query := o.QueryTable("key_word").Filter("type", 1).Limit(500)
	list := make([]*KeyWord, 0)
	query.All(&list)
	return list
}